<template>
  <div class="app-container">
    <div class="search-box">
      <el-input
        class="search-input"
        placeholder="用户名/手机号码/昵称/真实姓名"
      >
        <i slot="prefix" class="el-input__icon el-icon-search" />
      </el-input>
      <el-button class="search-btn" type="primary" @click="handleSearch()">
        搜索
      </el-button>
    </div>

    <!--表格-->
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="序号" prop="id" align="center" width="60">
        <template slot-scope="{row}">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column label="商品名称" prop="name" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="销量" prop="sellCount" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.sellCount }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" prop="status" align="center" width="80">
        <template slot-scope="{row}">
          <span v-if="row.status==1">上架中</span>
          <span v-else>已下架</span>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" prop="createTime" align="center" width="155">
        <template slot-scope="{row}">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="更新时间" prop="updateTime" align="center" width="155">
        <template slot-scope="{row}">
          <span>{{ row.updateTime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)">
            编辑
          </el-button>
          <el-button v-if="row.status!='deleted'" size="mini" type="danger" @click="handleDelete(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="paginations"
      background
      prev-text="上一页 "
      next-text="下一页"
      :page-size="pageSize"
      layout="slot, prev, pager, next"
      :total="total"
      @current-change="onCurrentChange"
    >
      <span class="totalCount">共{{ this.total }}条</span>
    </el-pagination>
  </div>
</template>

<script>

import { fetchList } from '@/api/product'

export default {
  name: 'Product',
  data() {
    return {
      list: null,
      tableKey: 0,
      listLoading: false,
      keyword: '',

      pageNum: 1,
      pageSize: 10,
      total: 10
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      const data = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        keyword: this.keyword
      }

      this.listLoading = true
      fetchList(data).then(res => {
        this.list = res.data.list
        this.total = res.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      })
    },

    handleSearch() {

    }
  }
}
</script>

<style lang="scss">

.paginations {
  margin-top:20px;
  text-align:center;
}

.totalCount {
  color: #666666;
  font-weight: normal;
  font-size: 14px;
  margin-right: 10px;
}

.search-box {
  margin-bottom: 10px;
  text-align:left;
}

.search-input{
    width: 360px;
    margin-right:10px;
}

</style>
